#include "scripting/scripting_api.h"
#include "scripting/scripting_module.h"
#include "utils/log.hpp"
#include "wren_base.hpp"
#include "wren_editor_extension.hpp"
#include "wren_function_extension.hpp"

bool ModuleInit()
{
    L_INFO("Wren Scripting Module Init...");
    auto &vm = WrenShared::SharedVM();
    (void)vm;
    // vm.runFromSource("example", "System.print(\"Wren Script Module Init..\")");
    return true;
}

void ModuleCleanup()
{
    auto &vm = WrenShared::SharedVM();
    // vm.runFromSource("example", "System.print(\"Wren Script Module Cleanup...\")");
    vm.gc();
    L_INFO("Wren Scripting Module Cleanup...");
}

IScript* BuildScript(const ScriptBuildInfo *info)
{
    RC_ERROR(nullptr, !(info && info->Valid()), "Invalid Script Build Info Passed!!!");

    if (strcmp(info->usage, "editor") == 0) {
        return WrenEditorExtension::create(EditorTargetFromString(info->usage_extra), info->title, info->code, info->file_path);
    } else if (strcmp(info->usage, "function") == 0) {
        return WrenFunctionExtension::create(info->title, info->code, info->file_path);
    }

    return nullptr;
}
